package com.example.yunbiji0314.service.iml;

import com.example.yunbiji0314.dao.GoodDao;
import com.example.yunbiji0314.pojo.Good;
import com.example.yunbiji0314.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class GoodServiceImpl implements GoodService {

    @Autowired
    private GoodDao goodDao;
    @Override
    public int zenggood(Good good) {
        int i=0;
        //根据aid和uid查询 这个人的文章在购物车中是否已经存在
        Good good1 = goodDao.findById(good);
        if(good1!=null) {
            //修改数量 旧数量加上1
            good.setCount(good1.getCount()+1);

            i = goodDao.updatecount(good);
        }else {
            //添加数据
            i = goodDao.zenggood(good);
        }

        return i;
    }

    @Override
    public List<Map> findByUserId(Integer id) {
        return goodDao.findByUserId(id);
    }
}
